package java6681.lesson14;

import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author Junichiro
 * @description 客户端键盘输入，服务器输出到文本文件
 * @date 2021-06-18 16:14
 **/
//java java6681.lesson14.TextClient6681
//javac -encoding UTF-8 java6681/lesson14/TextClient6681.java
public class TextClient6681 {
    public static void main(String[] args) throws IOException {
        Socket s = new Socket("192.168.43.65", 8899);
        // （1）使用Scanner从键盘输入文本
        Scanner sc = new Scanner(System.in);
        System.out.println("输入信息：");
        //（2）发送文本信息：用打印输出流包装Socket对象的输出流，将键盘输入的文本发送到服务端
        PrintStream printer = new PrintStream(s.getOutputStream(), true,"gbk");
        while (true) {
            if (sc.hasNext()) {
                String str = sc.next();
                printer.println(str);
                //（3）键盘输入stop，结束
                if ("stop".equals(str)) {
                    break;
                }
            }
        }
        s.close();
    }
}
